﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using ExtendModule;

namespace LabMS.Web.Equipment.Consum
{
    public partial class recipientslist : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            strPagePrivilege.Add("HCLY");//必须写在ispostback外
            strPagePrivilege.Add("HCGL");
            strPagePrivilege.Add("HCTJ");
            strPageUserType.Add("mana");
            if (!Page.IsPostBack)
            {
                bind("1=1 order by OperatDate desc");
                bindddl();
                IniPage();
            }
        }

        public void bind(string strWhere)
        {
            List<Model.SuppliesRecipients> listrescipientsmodule = new List<Model.SuppliesRecipients>();
            ExtendBLL.SuppliesRecipients berescipients = new ExtendBLL.SuppliesRecipients();
            listrescipientsmodule = berescipients.ExtendGetModuleList(strWhere);
            GridViewRConsum.DataSource = listrescipientsmodule;
            GridViewRConsum.DataBind();
        }

        public void bindddl()
        {
            LabMS.BLL.Lab blab = new LabMS.BLL.Lab();
            List<LabMS.Model.Lab> mLab = new List<LabMS.Model.Lab>();
            mLab = blab.GetModelList(" Lab_ParentID is null ");
            ddlLab.DataSource = mLab;
            ddlLab.DataTextField = "Lab_Name";
            ddlLab.DataValueField = "Lab_Code";
            ddlLab.DataBind();
            ddlLab.Items.Insert(0, new ListItem("", "null"));

        }

        public void IniPage()
        {
            tbTime1.Attributes.Add("onclick", "c.showMoreDay = false;c.show(this);");
            tbTime2.Attributes.Add("onclick", "c.showMoreDay = false;c.show(this);");

            tbTime1.Attributes.Add("readOnly", "-1");
            tbTime2.Attributes.Add("readOnly", "-1");
        }

        protected void GridViewConsum_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridViewRConsum.PageIndex = e.NewPageIndex;
            if (lbSearch.Text == "0")
            {
                bind("1=1 order by OperatDate desc");
            }
            else
            {
                string strWhere = " 1=1 ";
                if(tbLocation.Text.Trim()=="")
                {
                    tbLocationCode.Text = "";
                }
                if (!tbLocationCode.Text.Equals(""))
                {
                    strWhere += " and  EncodedWarehouse = '" + tbLocationCode.Text + "'";
                }
                if (!ddlLab.SelectedValue.Equals("null"))
                {
                    strWhere += " and Laboratory = '" + ddlLab.SelectedValue + "'";
                }
                strWhere += " and Name like '%" + tbCName.Text.Trim() + "%'";
                strWhere += " and Numbers like '%" + tbNumbers.Text.Trim() + "%'";
                strWhere += " and Teacher_Name like '%" + tbUPerson.Text.Trim() + "%'";
                if (!tbTime1.Text.Trim().Equals(""))
                {
                    strWhere += " and EncodedTime >= '" + tbTime1.Text.Trim() + "'";
                }
                if (!tbTime2.Text.Trim().Equals(""))
                {
                    DateTime dtTemp = new DateTime();
                    if (!DateTime.TryParse(tbTime2.Text.Trim(), out dtTemp))
                    {
                        dtTemp = DateTime.Today;
                    }
                    else
                    {
                        dtTemp.AddDays(1.0);
                    }
                    strWhere += " and EncodedTime >= '" + dtTemp.ToShortDateString() + "'";
                }
                bind(strWhere + " order by OperatDate desc");
            }
        }

        protected void GridViewConsum_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.RowType == DataControlRowType.DataRow)
            //{
            //    e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
            //    e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");
                
            //}
        }

        protected void btSearch_Click(object sender, EventArgs e)
        {
            string strWhere = " 1=1 ";
            if (tbLocation.Text.Trim() == "")
            {
                tbLocationCode.Text = "";
            }
            if (!tbLocationCode.Text.Equals(""))
            {
                strWhere += " and  EncodedWarehouse = '" + tbLocationCode.Text + "'";
            }
            if (!ddlLab.SelectedValue.Equals("null"))
            {
                strWhere += " and Laboratory = '" + ddlLab.SelectedValue + "'";
            }
            strWhere += " and Name like '%" + tbCName.Text.Trim() + "%'";
            strWhere += " and Numbers like '%" + tbNumbers.Text.Trim() + "%'";
            strWhere += " and Teacher_Name like '%" + tbUPerson.Text.Trim() + "%'";
            if (!tbTime1.Text.Trim().Equals(""))
            {
                strWhere += " and EncodedTime >= '"+tbTime1.Text.Trim()+"'";
            }
            if (!tbTime2.Text.Trim().Equals(""))
            {
                DateTime dtTemp = new DateTime();
                if (!DateTime.TryParse(tbTime2.Text.Trim(), out dtTemp))
                {
                    dtTemp = DateTime.Today;
                }
                else
                {
                    dtTemp.AddDays(1.0);
                }
                strWhere += " and EncodedTime <= '" + dtTemp.ToShortDateString() + "'";
            }
            bind(strWhere + " order by OperatDate desc");
            lbSearch.Text = "1";
        }

        protected void btReset_Click(object sender, EventArgs e)
        {
            ddlLab.SelectedIndex = 0;
            tbLocationCode.Text = "";
            tbLocation.Text = "";
            tbTime1.Text = "";
            tbTime2.Text = "";
            tbUPerson.Text = "";
            tbNumbers.Text = "";
            tbCName.Text = "";
            lbSearch.Text = "0";
            bind("1=1 order by OperatDate desc");
        }

       
    }
}
